﻿// Dlg2.cpp: 实现文件
//

#include "stdafx.h"
#include "ArcFaceDemo.h"
#include"ArcFaceDemoDlg.h"
#include "Dlg2.h"
#include "afxdialogex.h"
#include"Dlg1.h"


// CDlg2 对话框

IMPLEMENT_DYNAMIC(CDlg2, CDialogEx)

CDlg2::CDlg2(CWnd* pParent /*=nullptr*/)
	: CDialogEx(StuStat_2, pParent)
{
	
}

CDlg2::~CDlg2()
{
}

void CDlg2::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, stuList);
}


BEGIN_MESSAGE_MAP(CDlg2, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CDlg2::OnBnClickedButton1)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, &CDlg2::OnClickList1)
	ON_BN_CLICKED(IDC_BUTTON2, &CDlg2::OnClickedRemarkButton)
END_MESSAGE_MAP()


// CDlg2 消息处理程序


void CDlg2::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	statChange(ColIndex);
}


BOOL CDlg2::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	//初始化表
	CString str[] = { TEXT("姓名"),TEXT("人脸ID"),TEXT("学号")  ,TEXT("备注")};
	for (int i = 0; i < 4; i++)
	{
		//设置表头
		stuList.InsertColumn(i, str[i]);
		stuList.SetColumnWidth(i, 100);
	}

	//初始化RemarkDlg
	remarkdlg = new CRemarkDlg;
	remarkdlg->ShowWindow(false);
	
	//初始化按钮
	GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}




const int CDlg2::getColIndex() { return this->ColIndex; }


void CDlg2::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	this->ColIndex = pNMItemActivate->iItem;
	GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
	*pResult = 0;
}

void CDlg2::insertStu(CString name, CString FaceID, CString StuID)
{
	stuList.InsertItem(stuList.GetItemCount(), name);
	stuList.SetItemText(stuList.GetItemCount() - 1, 1, FaceID);
	stuList.SetItemText(stuList.GetItemCount() - 1, 2, StuID);
	stuList.SetItemText(stuList.GetItemCount() - 1, 3, TEXT(" "));
}


void CDlg2::OnClickedRemarkButton()
{
	// TODO: 在此添加控件通知处理程序代码
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
	remarkdlg->ShowWindow(true);
	remarkdlg->DoModal();
	if (remarkdlg->ifUPDATE)
	{
		stuList.SetItemText(ColIndex, 3, remarkdlg->getRemark());
	}
	remarkdlg->ifUPDATE = FALSE;
	ColIndex = -1;
}

int CDlg2::SearchByPicID(CString FaceID)
{
	int colIndforSearch=-1;
	for (int i = 0; i < stuList.GetItemCount(); i++)
	{
		if ((CString)stuList.GetItemText(i, 1) == FaceID) { colIndforSearch = i; break; }
		else {}
	}
	return colIndforSearch;
}

void CDlg2::statChange(int ColIndex)
{
	
	if (ColIndex < 0) { return; }
	CDlg1* tmpdlg = (CDlg1*)(((CArcFaceDemoDlg*)AfxGetMainWnd())->GetTabSheet()->getDialogPage(0));
	(tmpdlg->getList())->InsertItem(tmpdlg->getList()->GetItemCount(), (stuList.GetItemText(ColIndex, 0)));
	for (int i = 1; i <= 3; i++)
	{
		(tmpdlg->getList())->SetItemText(tmpdlg->getList()->GetItemCount() - 1, i, (stuList.GetItemText(ColIndex, i)));
	}
	stuList.DeleteItem(ColIndex);
	this->GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
}
